package controls;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

import view.InfoPanel;
import view.PlayPanel;

public class Connection {
	final int PORT = 1234;
	final String addressIp = "192.168.1.1";
	PlayPanel playPanel;
	Socket socket;
	InfoPanel infoPanel;

	public Connection(InfoPanel infoPanel, PlayPanel playPanel) {
		this.infoPanel = infoPanel;
		this.playPanel = playPanel;
	}

	public void makeServer() throws IOException {
		ServerSocket svSocket = new ServerSocket(PORT);
		socket = svSocket.accept();
	}

	public void makeClient() throws IOException {
		socket = new Socket(addressIp, PORT);
	}

	public void choiceHost() throws IOException {
		if (infoPanel.getHost() == true) {
			makeServer();
			playPanel.firstPlay = playPanel.XPLAYER;
		} else {
			makeClient();
			playPanel.firstPlay = playPanel.OPLAYER;
		}
	}

	public void play() throws IOException {
		choiceHost();

	}
}
